<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function getMostMoney(arr) {
        let money = [arr[0], Math.max(arr[0], arr[1])]
        for (let i = 2; i < arr.length; i++) {
          money[i] = Math.max(money[i - 1], money[i - 2] + arr[i])
        }
        return money[arr.length-1]
      }

      console.log(getMostMoney([2,9,8,3,3,1]))
    </script>
  </body>
</html>
